package com.naiterui.ehp.bs.patient.vo.patient;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;

import com.google.common.base.MoreObjects;
import org.slf4j.LoggerFactory;
import com.naiterui.ehp.bs.patient.exception.ExceptionCodes;
import com.naiterui.ehp.bs.patient.utils.StringUtil;
import com.naiterui.ehp.bs.patient.utils.exception.PatientBusinessException;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @author 王泽浩
 * @since 1.0.0
 */
@ApiModel(value = "AppraiseVO", description = "评价问诊接口")
public class AppraiseVO implements java.io.Serializable {

    private static final long serialVersionUID = -4164573924302807923L;

    private static final Logger LOGGER = LoggerFactory.getLogger(AppraiseVO.class);

    /**
     * 患者ID
     */
    @ApiModelProperty(value = "患者ID")
    private Long patientId;

    /**
     * consultId
     */
    @ApiModelProperty(value = "consultId")
    private Long consultId;

    /**
     * IM 会话ID
     */
    @ApiModelProperty(value = "会话ID")
    private String sessionId;

    /**
     * 评价级别，1、2、3、4、5 默认5星
     */
    @ApiModelProperty(value = "评价级别，1、2、3、4、5  默认5星")
    private Integer starLevel;

    /**
     * 评价内容
     */
    @ApiModelProperty(value = "评价内容")
    private String commentContent;

    /**
     * 打赏信息：（1:2元，2:3元，3:5元，4:8元多个用逗号分隔拼成一个字符串“1，2，3“）
     */
    @ApiModelProperty(value = "打赏信息：（1:2元，2:3元，3:5元，4:8元多个用逗号分隔拼成一个字符串“1，2，3“）")
    private String rewardType;

    /**
     * 支付标识（传当前时间时间戳（即毫秒数））
     */
    @ApiModelProperty(value = "支付标识（传当前时间时间戳（即毫秒数））")
    private Long extId;

    @ApiModelProperty(value = "生成打赏IP")
    private String ip;

    public Long getPatientId() {
        return this.patientId;
    }

    public void setPatientId(Long patientId) {
        this.patientId = patientId;
    }

    public Long getConsultId() {
        return this.consultId;
    }

    public void setConsultId(Long consultId) {
        this.consultId = consultId;
    }

    public String getSessionId() {
        return this.sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public Integer getStarLevel() {
        return this.starLevel;
    }

    public void setStarLevel(Integer starLevel) {
        this.starLevel = starLevel;
    }

    public String getCommentContent() {
        String commentStr = "";
        if (StringUtils.isNotBlank(this.commentContent)) {
            // 过滤表情，特殊字符
            commentStr = StringUtil.handleEmoji(this.commentContent);
            if (StringUtils.isBlank(commentStr)) {
                commentStr = "???";
            }
        }
        return commentStr;
    }

    public void setCommentContent(String commentContent) {
        this.commentContent = commentContent;
    }

    public String getRewardType() {
        return this.rewardType;
    }

    public void setRewardType(String rewardType) {
        this.rewardType = rewardType;
    }

    public Long getExtId() {
        return this.extId;
    }

    public void setExtId(Long extId) {
        this.extId = extId;
    }

    public String getIp() {
        if (StringUtils.isBlank(this.ip)) {
            return "127.0.0.1";
        }
        return this.ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    /**
     * 评价问诊校验参数
     * @throws PatientBusinessException 参数异常
     */
    public void validator() throws PatientBusinessException {
        // 参数校验
        if (this.patientId == null || (this.consultId == null && StringUtils.isBlank(this.sessionId)) || this.extId == null) {
            LOGGER.error("appraise consult; params error; patientId:{}, consultId:{},extId:{} _o:{}", this.patientId, this.consultId, this.extId);
            throw new PatientBusinessException(ExceptionCodes.PARAM_ERROR);
        }
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this).add("patientId", this.patientId).add("consultId", this.consultId).add("sessionId", this.sessionId)
                .add("starLevel", this.starLevel).add("commentContent", this.commentContent).add("rewardType", this.rewardType)
                .add("extId", this.extId).add("ip", this.ip).toString();
    }
}
